from PIL import Image
import os.path


def change(img_dir):
'''
111111
11111
'''
"""
1111
1111
"""
    im = Image.open(img_dir)
    w,h = im.size
#   print(w,h)
#   print(type(w))
    if w>1136:
        h = int((h/w)*1136)
        w = 1136

    if h>640:
        w = int((w/h)*640)
        h = 640
    im.thumbnail((w,h))
    return im


def img_list(dir):
''''''

''''''
""""""
    return [x for x in os.listdir(dir) if os.path.isfile(x) and (os.path.splitext(x)[1]=='.jpg' or os.path.splitext(x)[1]=='.jpeg')]


if __name__=='__main__':
    start_dir = '.'
    img_list = img_list(start_dir)
    print(img_list)
    img_dirs = []
    for img in img_list:
        img_dirs.append(os.path.join(start_dir,img))

    for n,img in enumerate(img_dirs):
        im = change(img)
        new_path=os.path.join(start_dir,"new_picture")
        new_path=os.path.join(new_path,"new_"+img_list[n])
        im.save(new_path)
